package com.itheima.mm.controller;

import com.itheima.mm.dao.CatalogDao;
import com.itheima.mm.entity.PageResult;
import com.itheima.mm.entity.QueryPageBean;
import com.itheima.mm.entity.Result;
import com.itheima.mm.pojo.Catalog;
import com.itheima.mm.pojo.Company;
import com.itheima.mm.pojo.Course;
import com.itheima.mm.service.CatalogService;
import com.itheima.mm.utils.DateUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/catalog")
public class CatalogController {
    @Autowired
    private CatalogService catalogService;
    @PostMapping("/findListByPage")
    public Result findListByPage(@RequestBody QueryPageBean queryPageBean){
        List<Catalog> catalogList=catalogService.findListByPage(queryPageBean);
        Long total =catalogService.findTotal(queryPageBean) ;
        return new Result(true,"获取学科目录列表成功",new PageResult(total,catalogList));
    }


    @PostMapping("/add")
    public Result add(@RequestBody Catalog catalog){
        catalog.setUserId(1);
        catalog.setCreateDate(DateUtils.parseDate2String(new Date()));
        catalogService.add(catalog);
        return new Result(true,"添加成功");
    }

    @GetMapping("/delete")
    public Result delete(@RequestParam("catalogId") Integer catalogId){
        catalogService.delete(catalogId);
        return new Result(true,"删除成功");
    }









}
